package com.hb.medical_research_system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.medical_research_system.common.Results;
import com.hb.medical_research_system.common.UserThreadLocal;
import com.hb.medical_research_system.entity.Collection;
import com.hb.medical_research_system.mapper.CollectionMapper;
import com.hb.medical_research_system.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hb
 * @description 针对表【collection】(收藏)的数据库操作Service实现
 * @createDate 2023-02-25 11:14:53
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection> implements CollectionService{

    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public Results add(Long articleId) {
        collectionMapper.insert(new Collection(UserThreadLocal.get().getUserId(), articleId));
        return Results.info(Results.SUCCESS,"收藏成功");
    }

    @Override
    public Results delete(Long articleId) {
        collectionMapper.deleteByUserIdandArticleId(UserThreadLocal.get().getUserId(), articleId);
        return Results.info(Results.SUCCESS,"删除成功");
    }
}




